package mop.gui.project;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JOptionPane;
import mop.controller.RemoveProjectController;
import mop.gui.GUI;
import mop.model.project.ProjectInterface;

/**
 * RemoveProjectAction
 * 
 * @author  Laurens
 */
public class RemoveProjectAction implements MouseListener
{
    private GUI gui;
    private RemoveProjectController removeProjectController;
    private ProjectInterface project;
    
    /**
     * Constructor.
     * 
     * @param   mainWindow
     * @param   removeProjectController
     * @param   project
     */
    public RemoveProjectAction(GUI gui, RemoveProjectController removeProjectController, ProjectInterface project)
    {
        this.gui = gui;
        this.removeProjectController = removeProjectController;
        this.project = project;
    }

    public void mouseClicked(MouseEvent e)
    {
        int result = JOptionPane.showConfirmDialog(null, 
                "Are you sure you want to remove this project?", "Are you sure?", JOptionPane.YES_NO_OPTION);
        
        if ( result == JOptionPane.YES_OPTION ) 
        {
            try {
                removeProjectController.removeProject(project.getId());
                gui.handleSuccess("Project removed!");
            } catch (Throwable exception) {
                gui.handleError(exception);
                return;
            }
            
            gui.getMainWindow().update();
        }
    }

    public void mousePressed(MouseEvent e)
    {
    }

    public void mouseReleased(MouseEvent e)
    {
    }

    public void mouseEntered(MouseEvent e)
    {        
    }

    public void mouseExited(MouseEvent e)
    {
    }
}